{extend name="public/layout"}

{block name="title"}分类添加{/block}

{block name="main"}
<body>
<div class="pd-20">
  {if $status == 'update'}
  <form action="{:U('sorting/update')}" method="post" class="form form-horizontal" id="sort_create" enctype="multipart/form-data">
  {else /}
  <form action="{:U('sorting/create')}" method="post" class="form form-horizontal" id="sort_create" enctype="multipart/form-data">
  {/if}
    <div class="row cl">
      <label class="form-label col-2"><span class="c-red">*</span>上级分类：</label>
      <div class="formControls col-5">
        <select class="select product-category-name input-text" name="pid">
            <option value="0" selected="selected">---- 顶级分类 ----</option>
            {foreach $list as $v}
              <option value="{$v.id}" {$res['pid'] == $v['id'] ? 'selected' : ''}>{$v.sname}</option>
            {/foreach}
        </select>
      </div>
      <div class="col-5"> </div>
    </div>
    <div class="row cl">
      <label class="form-label col-2"><span class="c-red">*</span>分类名称：</label>
      <div class="formControls col-5">
        <input type="text" class="input-text" placeholder="" id="user-name" name="sname" datatype="/.{1,20}/" errormsg="请输入分类名称" value="{$res.sname}"/>
      </div>
      <div class="col-5"> </div>
    </div>
    <div class="row cl">
      <label class="form-label col-2"><span class="c-red"><span class="c-red">*</span></span>分类图片：</label>
      <div class="formControls col-5">
        <span class="btn-upload form-group">
          <div id="upload"></div>
        </span>
      </div>
      <div class="col-5"> </div>
    </div>
    <div class="row cl">
      <label class="form-label col-2"><span class="c-red"></span>显示排序：</label>
      <div class="formControls col-5">
        <input type="text" class="input-text" name="sort" value="{$res.sort}" placeholder="输入一个不为负数的正整数，越大的靠前" datatype="n" errormsg="请输入一个正整数" />
      </div>
      <div class="col-5"> </div>
    </div>
    <div class="row cl">
      <div class="col-9 col-offset-2">
        <input name="update_time" value="{:time()}" type="hidden" />
        <input name="id" value="{$res.id}" type="hidden" />
        <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
      </div>
    </div>
  </form>
</div>
{/block}


{block name="js"}
    {load href="__ADMIN__/lib/Validform/5.3.2/Validform.min.js"}
    {load href="__ADMIN__/lib/Huploadify/jquery.Huploadify.js"}
    <script type="text/javascript">
        $(function(){
          $('#upload').Huploadify({
            auto:true,  //是否直接上传
            fileTypeExts:'*.jpg;*.png;', //文件格式
            multi:true,  //是否允许上传多个文件
            formData:{sid:{$res.id},type:'create'},  //同时提交的额外数据
            fileSizeLimit:'1MB',  //文件大小限制
            showUploadedPercent:false,//是否实时显示上传的百分比，如20%
            showUploadedSize:true,
            removeTimeout:9999999,
            uploader:'{:U("sorting/upload")}',
            buttonClass:'btn btn-primary upload-btn',
            onUploadStart:function(){
              //alert('开始上传');
              },
            onInit:function(){
              //alert('初始化');
              },
            onUploadComplete:function(){
                layer.alert('上传成功！',{
                    icon:1
                });
              },
            onDelete:function(file){
              console.log('删除的文件：'+file);
              console.log(file);
            }
            });
          });
        $("#sort_create").Validform({
          tiptype:4,
          ajaxPost:true,
          datatype:{
            "*6-20": /^[^\s]{6,20}$/,
          },
          callback:function(data){
            if(data.status == 'y'){
              var index = parent.layer.getFrameIndex(window.name);
              parent.$('.btn-refresh').click();
              parent.location.reload();
              parent.layer.close(index);
            }else{
              layer.alert(data.info ? data.info : '500', {
                icon: 2
              })
            }
          }
      });
    </script>
{/block}
